package org.cboard.dataprovider.config;

import java.util.List;
import java.util.Map;

/**
 * Created by zyong on 2017/1/9.
 */
public class AggConfig {

    private List<DimensionConfig> rows;
    private List<DimensionConfig> columns;
    private List<ConfigComponent> filters;
    private List<ValueConfig> values;


    private String linkJsonConfig;

    private String dyParams;

    private String linkParams = "";

    public String getDyParams() {
        return dyParams;
    }

    public void setDyParams(String dyParams) {
        this.dyParams = dyParams;
    }

    public String getLinkParams() {
        return linkParams;
    }

    /**
     * 前提：同一个看板中有被关联的图表
     *
     * @param map
     * @return
     */
    public AggConfig putLinkParam(Map<String, String> map) {

        if (!map.isEmpty()) {
            for (Map.Entry<String, String> m : map.entrySet()) {
                linkParams = linkParams + " and " + m.getKey().trim() + "='" + m.getValue().trim() + "'";
            }
        }
        if (!noLink()) {
            linkParams = linkParams.replaceFirst("and", "where");
        }
        return this;
    }


    public String getLinkJsonConfig() {
        return linkJsonConfig;
    }

    public void setLinkJsonConfig(String linkJsonConfig) {
        this.linkJsonConfig = linkJsonConfig;
    }

    public boolean noLink() {
        return linkParams == null || "".equals(linkParams);
    }

    public List<DimensionConfig> getRows() {
        return rows;
    }

    public void setRows(List<DimensionConfig> rows) {
        this.rows = rows;
    }

    public List<DimensionConfig> getColumns() {
        return columns;
    }

    public void setColumns(List<DimensionConfig> columns) {
        this.columns = columns;
    }

    public List<ConfigComponent> getFilters() {
        return filters;
    }

    public void setFilters(List<ConfigComponent> filters) {
        this.filters = filters;
    }

    public List<ValueConfig> getValues() {
        return values;
    }

    public void setValues(List<ValueConfig> values) {
        this.values = values;
    }
}
